﻿using ComposantRefentielV2.BLL;
using GeneralServices.Model;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;

namespace WpfApplication1.TestComposantV2
{
    public class BLLEmballage : IBLLReferentiel
    {
        #region Attribut(s)
        
        #endregion

        #region Propriété(s)

        public BaseRepository<EMB_EMBALLAGE> DAO { get; set; }

        #endregion

        #region Constructeur(s)

        public BLLEmballage(BaseRepository<EMB_EMBALLAGE> repository)
        {
            DAO = repository;
        }

        #endregion

        #region IBLLReferentiel<EMB_EMBALLAGE> Membres

        List<IDTO> IBLLReferentiel.SelectAllBusiness()
        {
            return DAO.All().ToList<IDTO>();
        }

        int IBLLReferentiel.SaveChanges(List<IDTO> list)
        {
            try
            {
                foreach (IDTO dto in list)
                    DAO.Save(dto);

                return DAO.UnitOfWork.Commit();
            }
            catch { throw; }
        }

        void IBLLReferentiel.RollBack()
        {
            DAO.RollBackAll();
        }

        int IBLLReferentiel.Remove(object element)
        {
            if (element is IDTO)
                return DAO.Delete(element as IDTO);
            return 0;
        }

        IDTO IBLLReferentiel.CreateElement()
        {
            return DAO.CreateEmpty();
        }

        IEnumerable<DbEntityValidationResult> IBLLReferentiel.GetValidationErrors()
        {
            return DAO.ContextBDD.GetValidationErrors();
        }

        #endregion
    }
}
